package boun.swe.bob.dao;

import boun.swe.bob.entities.Comment;
import boun.swe.bob.entities.Like;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Component;

import java.sql.SQLException;

/**
 * This DAO corresponds to comments table in database
 */
@Component
public class CommentsDao extends GenericDaoImpl<Comment, Integer>{

    private static final Logger LOG = Logger.getLogger(CommentsDao.class);

    /**
     * This method is used for deleting a comment
     *
     * @param commentId corresponds to comment ID in comments table
     */
    public void deleteComment(final int commentId) {
        hibernateTemplate.execute(new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query query = session.createSQLQuery("delete from comments where comment_id = ?");
                query.setInteger(0, commentId);
                query.executeUpdate();
                return null;
            }
        });
    }

}
